<?php

class Admin_RealcategoryController extends Zend_Controller_Action{

	public function init(){

		$this->_helper->layout->setLayout('admin/admin');
		 
	}
 	public function indexAction(){

         $params['page'] = $this->_getParam('page', 1);
         $params['limit'] =20;
         $cache = Core_Global::getCache();
         $pages = ceil(count($cache->get('RealCategory:ListIds')) / $params['limit']);
         $params['start'] = $params['page']*$params['limit'] - $params['limit'];
         $params['end'] = $params['start'] + $params['limit'];
         if($params['end']>count($cache->get('RealCategory:ListIds'))){
            $end = count($cache->get('RealCategory:ListIds'));
         }

         $realCategories =  Model_RealCategory::getAll($params);

         $this->view->assign('pages', $pages);
         $this->view->assign('RealCategories', $realCategories);
    }
    
    public function createAction(){
    	$post = $this->_request->getPost();

    	if($post){
    		$result = Model_RealCategory::create($post);
    		$this->_helper->json($result);
    	}else
    		$this->_helper->json(0);
    }
    
    public function updateAction(){
    	$post = $this->_request->getPost();
    	if($post){
    		$result = Model_RealCategory::update($post);
    		$this->_helper->json($result);
    	}else
    		$this->_helper->json(0);
    	
    }
    
    public function deleteAction(){
    	$catId = $this->_getParam('id');
    	$result = Model_RealCategory::delete($catId);

    	$this->_helper->json($result);
    }
    
		
}